program example_life_guard
use polymorphic_complextaylor
implicit none
integer nx,i,no,nv
type(real_8) t, x,dx,dtdx
real(dp) x0,dx0

open(unit=16,file='result_polymorph.txt')


write(6,*) "*********************   no  *****************************"
read(5,*) no
!no=3;
nv=1;
call init(no,nv)  
call alloc (t, x,dx,dtdx)
x0=0.0d0


123  x=x0+(1.d0.mono.1)

t=sqrt(x**2 + 50.d0**2) + sqrt((25.d0-x)**2 + 15.d0**2)/7.d0
dtdx=t%t.d.1


!call solve(dtdx%t,dx0)
call solve_with_map(dtdx%t,dx0)


write(6,*)  " dx0 = ",dx0
write(6,*)  " x0 before = ",x0

x0=x0+dx0
write(6,*)  " x0 after = ",x0
pause 
goto 123

call kill(t, x,dx,dtdx)

close(16)
end program example_life_guard

subroutine solve_with_map(t,dx0)
use polymorphic_complextaylor
type(taylor) t
real(dp) dx0
type(gmap) m,n
call alloc(m,n,n=1)

dx0=(t.sub.'0')
write(6,*) " present slope ",dx0
m%v(1)=t      



m=m.oo.(-1)

dx0=m%v(1).sub.'0'



call kill(m,n)

end subroutine solve_with_map

subroutine solve(t,dx0)
use polymorphic_complextaylor
type(taylor) t
real(dp) dx0

dx0=-(t.sub.'0')/(t.sub.'1')

end subroutine solve

